home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2000 September / september_2000.iso / intercd / root / ^Linux / cfengine-1.5.3 / src / log.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-08-09  |  4.9 KB  |  205 lines

  1. /* cfengine for GNU
  2.  
  3.         Copyright (C) 1995
  4.         Free Software Foundation, Inc.
  5.  
  6.    This file is part of GNU cfengine - written and maintained 
  7.    by Mark Burgess, Dept of Computing and Engineering, Oslo College,
  8.    Dept. of Theoretical physics, University of Oslo
  9.  
  10.    This program is free software; you can redistribute it and/or modify it
  11.    under the terms of the GNU General Public License as published by the
  12.    Free Software Foundation; either version 2, or (at your option) any
  13.    later version.
  14.  
  15.    This program is distributed in the hope that it will be useful,
  16.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.    GNU General Public License for more details.
  19.  
  20.   You should have received a copy of the GNU General Public License
  21.   along with this program; if not, write to the Free Software
  22.   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
  23.  
  24. */
  25. /*****************************************************************************/
  26. /*                                                                           */
  27. /* File: log.c                                                               */
  28. /*                                                                           */
  29. /*****************************************************************************/
  30.  
  31. #include "cf.defs.h"
  32. #include "cf.extern.h"
  33.  
  34. extern char CFLOCK[bufsize];
  35.  
  36. /*****************************************************************************/
  37.  
  38. CfLog(level,string,errstr)
  39.  
  40. enum cfoutputlevel level;
  41. char *string, *errstr;
  42.  
  43. { int endl = false;
  44.  
  45. if ((string == NULL) || (strlen(string) == 0))
  46.    {
  47.    return;
  48.    }
  49.  
  50.  switch(level)
  51.    {
  52.    case cfsilent:    if (! SILENT || VERBOSE || DEBUG || D2)
  53.                         {
  54.             ShowAction();
  55.             printf("%s: %s",VPREFIX,string);
  56.             endl = true;
  57.                         }
  58.                      break;
  59.  
  60.    case cfinform:    if (SILENT)
  61.                         {
  62.             return;
  63.                         }
  64.    
  65.                      if (INFORM || VERBOSE || DEBUG || D2)
  66.                         {
  67.             ShowAction();
  68.             printf("%s: %s",VPREFIX,string);
  69.             endl = true;
  70.                         }
  71.              
  72.              if (LOGGING && (getuid() == 0))
  73.             {
  74.             syslog(LOG_ERR,string,VFQNAME);
  75.  
  76.             if (strlen(errstr) != 0)
  77.                {
  78.                syslog(LOG_ERR,errstr,VFQNAME);
  79.                syslog(LOG_ERR,strerror(errno),VFQNAME);
  80.                }
  81.             }
  82.                      break;
  83.             
  84.    case cfverbose:   if (VERBOSE || DEBUG || D2)
  85.                         {
  86.             if ((errstr == NULL) || (strlen(errstr) > 0))
  87.                {
  88.                ShowAction();
  89.                printf("%s: %s",VPREFIX,string);
  90.                printf("%s: %s",VPREFIX,errstr);
  91.                endl = true;
  92.                }
  93.             else
  94.                {
  95.                ShowAction();
  96.                printf("%s: %s",VPREFIX,string);
  97.                endl = true;
  98.                }
  99.                         }
  100.                      break;
  101.  
  102.    case cfeditverbose: if (EDITVERBOSE || DEBUG)
  103.                           {
  104.               ShowAction();
  105.                  printf("%s: %s",VPREFIX,string);
  106.               endl = true;
  107.                           }
  108.                      break;
  109.  
  110.    case cflogonly:
  111.                      if (LOGGING && getuid() == 0)
  112.             {
  113.             syslog(LOG_INFO,string,VFQNAME);
  114.             
  115.             if ((errstr == NULL) || (strlen(errstr) > 0))
  116.                {
  117.                syslog(LOG_ERR,errstr,VFQNAME);
  118.                }
  119.             }
  120.              
  121.                      break;
  122.  
  123.    case cferror:
  124.                      printf("%s: %s",VPREFIX,string);
  125.  
  126.              if (LOGGING && (getuid() == 0))
  127.             {
  128.             syslog(LOG_ERR,string,VFQNAME);
  129.             }
  130.  
  131.              if (string[strlen(string)-1] != '\n')
  132.             {
  133.             printf("\n");
  134.             }
  135.              
  136.              if ((errstr != NULL) && (strlen(errstr) > 0))
  137.                         {
  138.             ShowAction();
  139.                 printf("%s: %s: %s\n",VPREFIX,errstr,strerror(errno));
  140.             endl = true;
  141.             
  142.             if (LOGGING && (getuid() == 0))
  143.                {
  144.                syslog(LOG_ERR,errstr,VFQNAME);
  145.                syslog(LOG_ERR,strerror(errno),VFQNAME);
  146.                }
  147.                         }
  148.              return;
  149.    }
  150.  
  151.  
  152.  if (endl && (string[strlen(string)-1] != '\n'))
  153.     {
  154.     printf("\n");
  155.     }
  156. }
  157.  
  158. /*****************************************************************************/
  159.  
  160. ResetOutputRoute (log,inform)
  161.  
  162. char log, inform;
  163.  
  164.   /* t = true, f = false, d = default */
  165.  
  166. {
  167. if ((log == 't') || (log == 'f') || (inform == 't') || (inform == 'f'))
  168.    {
  169.    INFORM_save = INFORM;
  170.    LOGGING_save = LOGGING;
  171.    
  172.    switch (log)
  173.       {
  174.       case 't': LOGGING = true;
  175.             break;
  176.       case 'f': LOGGING = false;
  177.             break;
  178.       }
  179.  
  180.    switch (inform)
  181.       {
  182.       case 't': INFORM = true;
  183.             break;
  184.       case 'f': INFORM = false;
  185.             break;
  186.       }
  187.    }
  188. else
  189.    {
  190.    INFORM = INFORM_save;
  191.    LOGGING = LOGGING_save;
  192.    }
  193. }
  194.  
  195. /*****************************************************************************/
  196.  
  197. ShowAction()
  198.  
  199. {
  200. if (SHOWACTIONS)
  201.    {
  202.    printf("%s:",CFLOCK);
  203.    }
  204. }
  205.